<%--
  Created by Jerry
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
	<title>ProjectBox</title>
</head>
<body>
<b>Hello!! ${user.firstName}, ${user.lastName}</b>&nbsp;&nbsp;&nbsp;<a href="<c:url value='/logout' />">Log out</a><br/>
<table width="1000" border="1" cellspacing="2" cellpadding="10">
	<tr>
		<td width="250"><center><a href="<c:url value='/announcement'/>">Annoucement</a></center></td>
		<td width="250"><center><a href="<c:url value='/myproject'/>">Project</a></center></td>
		<td width="250"><center><a href="">Search</a></center></td>
		<td width="250"><center><a href="<c:url value='/rule'/>">Rule</a></center></td>
	</tr>
	
	<tr>
		<td>
			<p><a href="<c:url value='/newproject' />">New Project</a></p>
      		<p><a href="<c:url value='/myproject' />">My Project</a></p>
      		<p><a href="<c:url value='/contribute' />">Contribute Project</a></p>
    		<p><a href="<c:url value='/project' />">Other Project</a></p>	
		</td>
		<td colspan="3">
			<a href="<c:url value='/project/${project.id}/' />">${project.name}</a>
			<c:choose>
            <c:when test="${folders != null}">           	
            	<c:forEach var="tfolder" items="${traceFolders}" varStatus="counter">
            		> <a href="<c:url value='/project/${project.id}/${tfolder.id}/' />">${tfolder.name}</a>
            	</c:forEach>
            	</c:when>
            </c:choose>
            <c:choose>
            <c:when test = "${folder != null}">
            	> ${folder.name}
            </c:when>
            </c:choose>
			<hr/>
			
			<table border="1" cellspacing="2" cellpadding="10">
			<c:choose>
            <c:when test="${folders != null}">           	
            	<c:forEach var="folder" items="${folders}" varStatus="counter">
            		<tr>
                        <td><a href="<c:url value='/project/${project.id}/${folder.id}/' />">${folder.name}</a></td>
                        <td>folder</td>
                        <td> - </td>
                        <td> - </td>
                        <td><a href="<c:url value='/project/${project.id}/${folder.id}/deleteFolder' />">Delete</a></td>
                    </tr>
            	</c:forEach>
            	</c:when>
            </c:choose>
			<c:choose>
            <c:when test="${resources != null}">           	
                <c:forEach var="resource" items="${resources}" varStatus="counter">
                    <tr>
                        <td>${resource.name}</td>
                        <td>${resource.type}</td>
                        <td>
                        	<script language="Javascript">
								nd = new Date(${resource.timeModified});
								document.write(nd.toLocaleDateString() + "<br/>" + nd.toLocaleTimeString());
						</script>
                        </td>
                        <td><a href="<c:url value='/project/${project.id}/download?rid=${resource.id}' />">Download</a></td>
                        <c:choose>
            			<c:when test="${resource.uid == user.id or project.mid == user.id}">
            				<c:choose>
            				<c:when test = "${folder != null}">
            					<td><a href="<c:url value='/project/${project.id}/${folder.id}/resource/delete?rid=${resource.id}' />">Delete</a></td>
            				</c:when>
            				<c:otherwise>
	                        	<td><a href="<c:url value='/project/${project.id}/resource/delete?rid=${resource.id}' />">Delete</a></td>
                        	</c:otherwise>
                        	</c:choose>
                        </c:when>
                        <c:otherwise>
                        	<td></td>
                        </c:otherwise>
        				</c:choose>
                    </tr>
                </c:forEach>               
            </c:when>
        	</c:choose>
        	</table>
        	<br/>
        	<h4>Create New Folder</h4>
        	<c:choose>
        		<c:when test="${folder != null}" >
        			<h1>folderID is not null</h1>
        			<form action="<c:url value='/project/${project.id}/${folder.id}/createFolder' />" method="post">
        				<label>File Name</label>
        				<input type="text" name="folderName"  width='60' />
        				<input type="submit" name="submit" value="Add" />
        			</form>
        		</c:when>
        		<c:otherwise>
        			<h1>folderID is null</h1>
        			<form action="<c:url value='/project/${project.id}/createFolder' />" method="post">
        				<label>File Name</label>
        				<input type="text" name="folderName"  width='60' />
        				<input type="submit" name="submit" value="Add" />
        			</form>
        		</c:otherwise>	
        	</c:choose>
        	<h4>Add New Resource</h4>  
        	<c:choose>
        		<c:when test="${folder == null}" >
        			<form action="<c:url value='/project/${project.id}/upload' />" method="post" enctype="multipart/form-data">
        				<table width="60%" border="1" cellspacing="0">
            				<tr>
                				<td width="35%"><strong>File to upload</strong></td>
                				<td width="65%"><input type="file" name="file" /></td>
            				</tr>
            				<tr>
                				<td><strong>Description</strong></td>
                				<td><input type="text" name="description" width="60" /></td>
            				</tr>
            				<tr>
                				<td>&nbsp;</td>
                				<td><input type="submit" name="submit" value="Add"/></td>
            				</tr>
        				</table>
    				</form>
        		</c:when>
        		<c:otherwise>
        			<form action="<c:url value='/project/${project.id}/${folder.id}/upload' />" method="post" enctype="multipart/form-data">
        				<table width="60%" border="1" cellspacing="0">
            				<tr>
                				<td width="35%"><strong>File to upload</strong></td>
                				<td width="65%"><input type="file" name="file" /></td>
            				</tr>
            				<tr>
                				<td><strong>Description</strong></td>
                				<td><input type="text" name="description" width="60" /></td>
            				</tr>
            				<tr>
                				<td>&nbsp;</td>
                				<td><input type="submit" name="submit" value="Add"/></td>
            				</tr>
        				</table>
    				</form>
        		</c:otherwise>
        	</c:choose>	     	
		</td>
		
	</tr>
</table>
</body>
</html>